﻿using EShopV20.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EShopV20.Areas.Adm.Controllers
{
    public class PermissionController : Controller
    {
        ApplicationDbContext sdb = new ApplicationDbContext();
        EShopV20DbContext db = new EShopV20DbContext(); 
        //
        // GET: /Adm/Permission/
        public ActionResult Index()
        {
            ViewBag.Roles = sdb.Roles;
            ViewBag.WebActions = db.WebActions;
            ViewBag.Permissions = db.Permissions.ToList();
            return View();
        }

        public ActionResult Update(String RoleId, int ActionId)
        {
            var perm = db.Permissions
                .Single(p => p.RoleId == RoleId && p.WebActionId == ActionId);
            perm.Allow = !perm.Allow;
            db.SaveChanges();

            return Content("");
        }
	}
}